<?php

$rank_check = 1;
$page_title = "Searching for Wild Pets";
include "header.inc.php";

$game = $_GET["game"];

$findSearch = fetch("SELECT * FROM search_pets2 WHERE userid = '$userid' AND game = '$game'");
if (!$findSearch[id])
{
	mysql_query("DELETE FROM search_pets2 WHERE userid = '$userid' AND game = '$game'");
	die(header(error("search_for_pets.php?game=$game","You are not searching right now.")));
}

if ($findSearch[moves_left] <= 0)
{
	mysql_query("DELETE FROM search_pets2 WHERE userid = '$userid' AND game = '$game'");
	die(header(error("search_for_pets.php?game=$game","You ran out of moves. You must pay another 750 $pointsVar to start exploring again.")));
}

print "$openHTML";

$x = $findSearch[x_cord];
$y = $findSearch[y_cord];
$cord = "$x$y";
$show[$cord] = "<center><font size=+2>X</font></center>";

if (!$findSearch[found])
{
$mainCell = "
<FONT SIZE=\"-1\"><TABLE BGCOLOR=\"#009900\" background=\"images/games/explore/grasstile.gif\" CELLSPACING=0 CELLPADDING=0 WIDTH=400 HEIGHT=400>
   <TR BGCOLOR=\"#666666\">
      <TD ROWSPAN=10 WIDTH=20 HEIGHT=400>
         <P></P>
      </TD>
      <TD COLSPAN=8 WIDTH=360 HEIGHT=20>
         <P></P>
      </TD>
      <TD ROWSPAN=10 WIDTH=20 HEIGHT=400>
         <P></P>
      </TD>
   </TR>
   <TR><TD WIDTH=45 HEIGHT=45>
         <P>$show[11]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[12]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[13]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[14]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[15]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45 BGCOLOR=\"#0000FF\">
         <P><img src=images/games/explore/watertile.gif></P>
      </TD>
      <TD WIDTH=45 HEIGHT=45 BGCOLOR=\"#0000FF\">
         <P><img src=images/games/explore/watertile.gif></P>
      </TD>
      <TD WIDTH=45 HEIGHT=45 BGCOLOR=\"#0000FF\">
         <P><img src=images/games/explore/watertile.gif></P>
      </TD>
   </TR>
   <TR><TD WIDTH=45 HEIGHT=45>
         <P>$show[21]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[22]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[23]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[24]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[25]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[26]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[27]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45 BGCOLOR=\"#0000FF\">
         <P><img src=images/games/explore/watertile.gif></P>
      </TD>
   </TR>
   <TR><TD WIDTH=45 HEIGHT=45>
         <P>$show[31]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[32]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[33]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[34]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[35]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[36]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[37]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[38]</P>
      </TD>
   </TR>
   <TR><TD WIDTH=45 HEIGHT=45 BGCOLOR=\"#0000FF\">
         <P><img src=images/games/explore/watertile.gif></P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[42]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[43]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[44]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[45]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[46]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[47]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[48]</P>
      </TD>
   </TR>
   <TR><TD WIDTH=45 HEIGHT=45 BGCOLOR=\"#0000FF\">
         <P><img src=images/games/explore/watertile.gif></P>
      </TD>
      <TD WIDTH=45 HEIGHT=45 BGCOLOR=\"#0000FF\">
         <P><img src=images/games/explore/watertile.gif></P>
      </TD>
      <TD WIDTH=45 HEIGHT=45 BGCOLOR=\"#0000FF\">
         <P><img src=images/games/explore/watertile.gif></P>
      </TD>
      <TD WIDTH=45 HEIGHT=45 BGCOLOR=\"#0000FF\">
         <P><img src=images/games/explore/watertile.gif></P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[55]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[56]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[57]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[58]</P>
      </TD>
   </TR>
   <TR><TD WIDTH=45 HEIGHT=45>
         <P>$show[61]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[62]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45 BGCOLOR=\"#0000FF\">
         <P><img src=images/games/explore/watertile.gif></P>
      </TD>
      <TD WIDTH=45 HEIGHT=45 BGCOLOR=\"#0000FF\">
         <P><img src=images/games/explore/watertile.gif></P>
      </TD>
      <TD WIDTH=45 HEIGHT=45 BGCOLOR=\"#0000FF\">
         <P><img src=images/games/explore/watertile.gif></P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[66]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[67]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[68]</P>
      </TD>
   </TR>
   <TR><TD WIDTH=45 HEIGHT=45>
         <P>$show[71]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[72]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[73]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[74]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[75]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[76]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[77]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[78]</P>
      </TD>
   </TR>
   <TR><TD WIDTH=45 HEIGHT=45>
         <P>$show[81]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[82]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[83]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[84]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[85]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[86]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[87]</P>
      </TD>
      <TD WIDTH=45 HEIGHT=45>
         <P>$show[88]</P>
      </TD>
   </TR>
   <TR BGCOLOR=\"#666666\"><TD COLSPAN=8 WIDTH=360 HEIGHT=20>
         <P></P>
      </TD>
   </TR>
</TABLE>
</FONT>
";
}

if ($findSearch[found] == "item")
{
$findItem2 = fetch("SELECT * FROM items2 WHERE item_name = '$findSearch[found_what]' AND game = '$game'");
mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','$findItem2[id]','$findItem2[parts]','$game')");

mysql_query("UPDATE search_pets2 SET found = '' WHERE userid = '$userid' AND game = '$game'");
mysql_query("UPDATE search_pets2 SET found_what = '' WHERE userid = '$userid' AND game = '$game'");

$mainCell = "

<CENTER><TABLE BGCOLOR=\"$tableOutline\" CELLSPACING=1 CELLPADDING=0 WIDTH=320 HEIGHT=300>
   <TR BGCOLOR=\"$topAndBottomBG\">
      <TD HEIGHT=45>
         <CENTER><FONT SIZE=\"+2\" COLOR=\"$topAndBottomText\"><B>You found an
         item!!</B></FONT></CENTER>
      </TD>
   </TR>
   <TR>
      <TD HEIGHT=30 BGCOLOR=\"$topAndBottomBG\">
         <CENTER><FONT SIZE=\"-2\">Congratulations, you found a $findItem2[item_name]!</FONT></CENTER>
      </TD>
   </TR>
   <TR>
      <TD HEIGHT=200 BGCOLOR=\"$maincellColor\">
         <CENTER><img src=images/user_images/opg_$game/items/item_$findItem2[id].gif><BR>
         <B>$findItem2[item_name]</B>

         <P><FONT SIZE=\"-1\"><I>$findItem2[item_desc]</I></FONT></P></CENTER>
      </TD>
   </TR>
   <TR BGCOLOR=\"$topAndBottomBG\">
      <TD HEIGHT=25>
         <CENTER><A HREF=\"searching_for_pets.php?game=$game\"><FONT COLOR=\"$topAndBottomText\">Back
         to Searching!</FONT></A></CENTER>
      </TD>
   </TR>
</TABLE>
</CENTER>

";
}

if ($findSearch[found] == "net")
{

if ($findSearch[found_what] == "Basic Net")
{
	mysql_query("UPDATE search_pets2 SET basic_nets=$findSearch[basic_nets]+1 WHERE userid = '$userid' AND game = '$game'");
	$netImage = "basicnet.jpg";
}

if ($findSearch[found_what] == "Electric Net")
{
	mysql_query("UPDATE search_pets2 SET elec_nets=$findSearch[elec_nets]+1 WHERE userid = '$userid' AND game = '$game'");
	$netImage = "electricnet.jpg";
}

if ($findSearch[found_what] == "Magic Net")
{
	mysql_query("UPDATE search_pets2 SET magic_nets=$findSearch[magic_nets]+1 WHERE userid = '$userid' AND game = '$game'");
	$netImage = "magicnet.jpg";
}

mysql_query("UPDATE search_pets2 SET found = '' WHERE userid = '$userid' AND game = '$game'");
mysql_query("UPDATE search_pets2 SET found_what = '' WHERE userid = '$userid' AND game = '$game'");

$mainCell = "

<CENTER><TABLE BGCOLOR=\"$tableOutline\" CELLSPACING=1 CELLPADDING=0 WIDTH=320 HEIGHT=300>
   <TR BGCOLOR=\"$topAndBottomBG\">
      <TD HEIGHT=45>
         <CENTER><FONT SIZE=\"+2\" COLOR=\"$topAndBottomText\"><B>You found a
         net!!</B></FONT></CENTER>
      </TD>
   </TR>
   <TR>
      <TD HEIGHT=30 BGCOLOR=\"$topAndBottomBG\">
         <CENTER><FONT SIZE=\"-2\">Congratulations, you found a $findSearch[found_what]!</FONT></CENTER>
      </TD>
   </TR>
   <TR>
      <TD HEIGHT=200 BGCOLOR=\"$maincellColor\">
         <CENTER><img src=images/games/explore/$netImage></CENTER>
      </TD>
   </TR>
   <TR BGCOLOR=\"$topAndBottomBG\">
      <TD HEIGHT=25>
         <CENTER><A HREF=\"searching_for_pets.php?game=$game\"><FONT COLOR=\"$topAndBottomText\">Back
         to Searching!</FONT></A></CENTER>
      </TD>
   </TR>
</TABLE>
</CENTER>

";
}


if ($findSearch[found] == "pet")
{
	$findSpecies = fetch("SELECT * FROM pets2 WHERE name = '$findSearch[found_what]' AND game = '$game'");
	$mainCell = "

	<CENTER><TABLE BGCOLOR=\"$tableOutline\" CELLSPACING=1 CELLPADDING=0 WIDTH=350 HEIGHT=300>
   <TR BGCOLOR=\"$topAndBottomBG\">
      <TD HEIGHT=45>
         <CENTER><FONT SIZE=\"+2\" COLOR=\"$topAndBottomText\"><B>--You Found a
         Wild Pet!--</B></FONT></CENTER>
      </TD>
   </TR>
   <TR BGCOLOR=\"$maincellColor\">
      <TD HEIGHT=175>
         <CENTER><img src=images/user_images/opg_$game/pets/pet_$findSpecies[id].gif><BR>
         <b>$findSpecies[name]</b></CENTER>
      </TD>
   </TR>
   <TR BGCOLOR=\"$topAndBottomBG\">
      <TD HEIGHT=40>
         <CENTER><FONT COLOR=\"$topAndBottomText\"><A HREF=\"searching_catch_pet.pro.php?game=$game&act=catch\">Try
         to catch the $findSpecies[name]!</A></CENTER>
      </TD>
   </TR>
   <TR BGCOLOR=\"$topAndBottomBG\">
      <TD HEIGHT=40>
         <CENTER><A HREF=\"searching_catch_pet.pro.php?game=$game&act=run\">Run
         from the $findSpecies[name]!</A></CENTER>
      </TD>
   </TR>
</TABLE>
</CENTER>

	";
}

if ($findSearch[found] == "pet2")
{
	$findSpecies = fetch("SELECT * FROM pets2 WHERE name = '$findSearch[found_what]' AND game = '$game'");

	$getitems = mysql_query("SELECT * FROM usersitems2 WHERE owner = '$userid' AND game = '$game' ORDER BY item_id");
	while ($getitems2 = mysql_fetch_array($getitems))
	{
		$get_item = fetch("SELECT * FROM items2 WHERE id = '$getitems2[item_id]' AND game = '$game'");
		if ($get_item[item_type] == "food")
		{
			$itemList .= "<option value=$getitems2[id]>$get_item[item_name]";
		}
	}

	$mainCell = "
	<CENTER><TABLE BGCOLOR=\"$tableOutline\" CELLSPACING=1 CELLPADDING=0 WIDTH=350 HEIGHT=300>
   <TR BGCOLOR=\"$topAndBottomBG\">
      <TD HEIGHT=45>
         <CENTER><FONT SIZE=\"+2\" COLOR=\"$topAndBottomText\"><B>--Catch the Wild
         Pet!!--</B></FONT></CENTER>
      </TD>
   </TR>
   <TR BGCOLOR=\"$maincellColor\">
      <TD HEIGHT=175>
         <CENTER><img src=images/user_images/opg_$game/pets/pet_$findSpecies[id].gif><BR>
         <B>$findSpecies[name]</B> - Level $findSearch[found_what2]<BR>
         <FONT SIZE=\"-1\"><a href=searching_catch_pet.pro.php?game=$game&act=run>Run from $findSpecies[name]!!</a></FONT></CENTER>
      </TD>
   </TR>
   <TR BGCOLOR=\"$topAndBottomBG\">
      <TD HEIGHT=40>
         <CENTER><FONT SIZE=\"-1\" COLOR=\"$topAndBottomText\">Throw a net:<BR>
         </FONT><A HREF=\"searching_catch_pet.pro.php?game=$game&act=net&net=basic\"><FONT SIZE=\"-1\">Basic
         Net</FONT></A><FONT SIZE=\"-1\" COLOR=\"$topAndBottomText\"> | </FONT><A HREF=\"searching_catch_pet.pro.php?game=$game&act=net&net=electric\"><FONT SIZE=\"-1\">Electric
         Net</FONT></A><FONT SIZE=\"-1\" COLOR=\"$topAndBottomText\"> | </FONT><A HREF=\"searching_catch_pet.pro.php?game=$game&act=net&net=magic\"><FONT SIZE=\"-1\">Magic Net</FONT></A></CENTER>
      </TD>
   </TR>
   <TR BGCOLOR=\"$topAndBottomBG\">
      <TD HEIGHT=40>
         <CENTER><FONT SIZE=\"-1\" COLOR=\"$topAndBottomText\"><FORM ACTION=\"searching_catch_pet.pro.php?game=$game&act=bait\" METHOD=POST>
            <CENTER><FONT SIZE=\"-1\" COLOR=\"$topAndBottomText\">Throw some food:<BR>
            <SELECT NAME=\"throw_food\">
               <OPTION>Choose an Item
               $itemList
            </SELECT> <INPUT TYPE=submit NAME=Submit VALUE=\"Throw Food!\"></FONT></CENTER>
         </FORM></FONT></CENTER>
      </TD>
   </TR>
</TABLE>
</CENTER>
	";
}

if ($findSearch[found] == "caught_pet")
{
	$findSpecies = fetch("SELECT * FROM pets2 WHERE name = '$findSearch[found_what]' AND game = '$game'");

	if ($net == "basic") { $netimage = "<img src=images/games/explore/basicnet.jpg"; }
	if ($net == "electric") { $netimage = "<img src=images/games/explore/electricnet.jpg"; }
	if ($net == "magic") { $netimage = "<img src=images/games/explore/magicnet.jpg"; }

	$mainCell = "
	<CENTER><TABLE BGCOLOR=\"$tableOutline\" CELLSPACING=1 CELLPADDING=0 WIDTH=400 HEIGHT=300>
   <TR BGCOLOR=\"$topAndBottomBG\">
      <TD HEIGHT=45>
         <CENTER><FONT SIZE=\"+2\" COLOR=\"$topAndBottomText\"><B>--You Caught the
         Pet!--</B></FONT></CENTER>
      </TD>
   </TR>
   <TR BGCOLOR=\"$maincellColor\">
      <TD HEIGHT=220>
         <CENTER>$netimage <img src=images/user_images/opg_$game/pets/pet_$findSpecies[id].gif><BR>
         <B>$findSpecies[name]</B></CENTER>
      </TD>
   </TR>
   <TR BGCOLOR=\"$topAndBottomBG\">
      <TD HEIGHT=35>
         <CENTER><FONT SIZE=\"-1\" COLOR=\"$topAndBottomText\"><FORM ACTION=\"searching_caught_pet.pro.php?game=$game&net=$net\" METHOD=POST>
            <CENTER><FONT SIZE=\"-1\" COLOR=\"$topAndBottomText\">Name pet: <input type=text size=16 maxlength=16 name=petname>
            <INPUT TYPE=submit NAME=Submit VALUE=\"Name Pet!\"></FONT></CENTER>
         </FORM></FONT></CENTER>
      </TD>
   </TR>
</TABLE>
</CENTER>
	";
}

ECHO <<<END
<br>
<P align=center>

<TABLE CELLSPACING=0 CELLPADDING=0 WIDTH=520 HEIGHT=400>
<tr>
<td width=120>

<p>
<b>Moves:</b> $findSearch[moves_left]/100<br>
<b>Nets:</b> $findSearch[basic_nets]/10<br>
<b>Elec. Nets:</b> $findSearch[elec_nets]/5<br>
<b>Magic.Nets:</b> $findSearch[magic_nets]/5
</p>

<p align=center>
<a href=searching_for_pets.pro.php?game=$game&act=move&move=up>Up</a><br>
<a href=searching_for_pets.pro.php?game=$game&act=move&move=left>Left</a> | <a href=searching_for_pets.pro.php?game=$game&act=move&move=right>Right</a><br>
<a href=searching_for_pets.pro.php?game=$game&act=move&move=down>Down</a>
</p>

<p><a href='finish_search.pro.php?game=$game&finish=search' onClick="if ( !confirm ('Are you sure you want to finish searching now??') ) { return false; }">FINISH EXPLORING</a></p>

</td>
<td width=400>

$mainCell
</td>
</tr>
</table>
</P>

END;

print "$closeHTML";
?>